home *** CD-ROM | disk | FTP | other *** search
- Path: mayne.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
- Subject: Re: Seek unix2dos.c OR help with tr
- Date: 21 Mar 1996 11:53:33 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4isc3tINNifd@mayne.ugrad.cs.ubc.ca>
- References: <danpop.826917054@rscernix> <4is3c3$jmp@ns.broadvision.com>
- NNTP-Posting-Host: mayne.ugrad.cs.ubc.ca
-
- In article <4is3c3$jmp@ns.broadvision.com>,
- Patrick Horgan <patrick@broadvision.com> wrote:
- >In article <danpop.826917054@rscernix>, danpop@mail.cern.ch (Dan Pop) writes:
- >>Moreover, 0x1f is not a magic number _in this context_ any more than 2
- >>is a magic number in a binary search algorithm or 3.1415926 is a magic
- >>number when computing the circumference of a circle. All of them are
- >>natural constants
- >
- >I agree...and it's the way I would do it as well.
- >
- >>
- >>As for Kazimir's example, a "better" definition would be:
- >>
- >>#define CTRL(C) ((C) - 'A' + 1)
- >
- >If I went down this path I'd choose ((C) - '@' )...somehow the + 1 seems as if it
- >will lead to further silly misunderstandings by junior programmers...I much prefer
- >anding off the upper bits though...anding with 0x3f is better and even works for
- >characters generated on some keyboards whose code is over 127...the subtraction
- >method won't.
-
- Oops. I messed up on that one. What I actually use is ``- 64''. In my zeal to
- conceal my use of a magic constant from a thread which condemns their use, I
- messed up! :)
-
- Here is what I actually have in one header file:
-
- #define CTRL(X) ((X)-64)
-
- Shame on me! :)
-
- I'd only use such a thing if I was certain that there is a necessary dependency
- in the program on the ascii character set. In this case, the program in
- question used the curses library, and I wanted to check for particular
- control keys, which I bound to various commands.
- --
-
-